#include <jsoncpp/json/json.h>
#include <sstream>
#include <memory>

class JsonUtil
{
public:
    static bool Serialize(Json::Value &root, std::string *str)
    {
        Json::StreamWriterBuilder builder;
        std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());

        std::stringstream ss;
        if (writer->write(root, &ss) != 0)
        {
            return false;
        }
        *str = ss.str();
        return true;
    }

    static bool UnSerialize(Json::Value &root, const char *str,size_t len)
    {
        Json::CharReaderBuilder builder;
        std::unique_ptr<Json::CharReader> reader(builder.newCharReader());

        std::string err;
        if (reader->parse(str, str+len, &root, &err) == false)
        {
            return false;
        }
        return true;
    }
};